<?php

class User_Backend_Security_Delete extends Backend_Component_Delete
{
    
    /**
    * Admin ID.
    * 
    * @var integer
    */
    private $_id;
    
    /**
     * Start filter.
     *
     */
    public function process() 
    {
        $this->_id = (int)Application::getRequest()->get('id');
        
        parent::process();
    }
    
    /**
     * @desc Реализация обработки пользовательского запроса.
     *
     */
    protected function _delete() 
    {
        $query = '
            DELETE
                   `s_s`, `s_a` 
              FROM 
                   `system_admin` `s_a`, `system_subject` `s_s` 
             WHERE 
                   `s_s`.`id` = `s_a`.`subject_id` 
               AND 
                   `s_a`.`id` = ' . $this->_id;
        
        database::query($query);
        return database::affectedRows() > 0;
    }
    
    /**
    * Deny self delete.
    * 
    */
    protected function _allowed() 
    {
        $allowed = $this->_id != Security_Session::getProfileId(Security_Subject::ADMIN);
        
        return parent::_allowed() && $allowed;
    }
    
}
